package zuoye;

import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.Enumeration;

public class GetCount extends HttpServlet {
Integer a=0,b=0,c=0,d=0;
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
//        resp.setHeader("Content-Type", "text/html;charset=UTF-8");
        resp.setCharacterEncoding("GBK");
        ServletContext servletContext = this.getServletContext();
        String referer = req.getHeader("Referer");
        if (referer.endsWith("a.html")) {
                servletContext.setAttribute("a.html",++a);
        }else if (referer.endsWith("b.html")) {
                servletContext.setAttribute("b.html",++b);
                    }else if (referer.endsWith("c.html")) {
                servletContext.setAttribute("c.html",++c);
        }else if (referer.endsWith("d.html")) {
                servletContext.setAttribute("d.html",1);
        }else  {
            Integer e = (Integer) servletContext.getAttribute("e.html");
            if (e == null) {
                servletContext.setAttribute("e.html",1);
            } else {
                servletContext.setAttribute("e.html",++e);
            }
        }

        Integer e = (Integer) servletContext.getAttribute("e.html");
                String froma = "来自a页面的点击量为" + a;
        String fromb = "来自b页面的点击量为" + b;
        String fromc = "来自c页面的点击量为" + c;
        String fromd = "来自d页面的点击量为" + d;
        String frome = "来自未知页面的点击量为" + e;
        System.out.println(froma);
        System.out.println(fromb);
        System.out.println(fromc);
        System.out.println(fromd);
        System.out.println(frome);

        String s="<a3>"+froma+"</a3><br><a3>"+fromb+"</a3><br><a3>"+fromc+"</a3><br><a3>"+fromd+"</a3><br><a3>"+frome+"</a3><br>";
        resp.getWriter().write(s);

    }


}
